home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5145 < prev    next >
Encoding:
Text File  |  1996-08-06  |  899 b   |  54 lines

  1. Path: frco.com!usenet
  2. From: Jadam@tcmail.frco.com (Jim Adam)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Gurus! Is it correct?
  5. Date: 2 Feb 1996 19:10:54 GMT
  6. Organization: Fisher Rosemount Systems
  7. Message-ID: <4etnju$6gn@rolaids.frco.com>
  8. References: <4eqvtg$cg5@israel-info.datasrv.co.il>
  9. NNTP-Posting-Host: primrose.frco.com
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. In article <4eqvtg$cg5@israel-info.datasrv.co.il>, dmitry@enigma.co.il 
  14. says...
  15.  
  16. >Is next code is correct from point of view of pure C++ ?
  17.  
  18. >class A
  19. >{
  20. >};
  21.  
  22. >class B
  23. >{
  24. >};
  25.  
  26. >class C : public A, public B
  27. >{
  28. >};
  29.  
  30. >A* pA = new C;
  31. >B* pB = new C;
  32.  
  33. >delete pA;
  34. >delete pB;
  35.  
  36. ==========================
  37.  
  38. This is correct.  However, to ensure the destructor for class
  39. C gets called correctly, class A and B both need virtual 
  40. destructors.
  41.  
  42. E.g., 
  43.  
  44.   class A
  45.   {
  46.     public:
  47.       virtual ~A();
  48.   };
  49.  
  50. And likewise for class B.   
  51.  
  52. Jim
  53.  
  54.